import http from '@/utils/http';

export function getAllStudent() {
  return http({
    url: '/getStudents.do',
  });
}
// 删除学生
export function deleteSelectStudent(ids: number[] | string[]) {
  return http({
    url: '/deleteStudents.do',
    method: 'post',
    data: [...ids.map((id) => ({ key: id }))],
  });
}
// 修改用户信息
export function modifyStudentInfo(data) {
  return http({
    url: '/updateStudent.do',
    method: 'post',
    data: {
      key: data.id,
      ...data,
    },
  });
}
// 添加学生
export function addStudent(data: {
  username: string;
  password: string;
  sex: string;
  id_card: string;
  status: number;
  class_name: string;
  tel: string;
  address: string;
}) {
  return http({
    url: '/addStudent.do',
    method: 'post',
    data: data,
  });
}

export function getAllClass() {
  return http({
    url: '/getClasses.do',
  });
}

export function deleteSelectClass(ids: number[] | string[]) {
  return http({
    url: '/deleteClasses.do',
    method: 'post',
    data: [...ids.map((id) => ({ key: id }))],
  });
}

export function addClass(data: {
  class_name: string;
  class_teacher: string;
  status: number | string;
  major_name: string;
}) {
  return http({
    url: '/addClass.do',
    method: 'post',
    data: data,
  });
}

export function modifyClass(data: {
  class_name: string;
  class_teacher: string;
  status: string | number;
  id: number;
  major_name: string;
}) {
  return http({
    url: '/updateClass.do',
    method: 'post',
    data: {
      key: data.id,
      ...data,
    },
  });
}

export function getMajors() {
  return http({
    url: '/getMajors.do',
  });
}

export function deleteMajors(id: number[] | string[]) {
  return http({
    url: '/deleteMajors.do',
    method: 'post',
    data: [...id.map((id) => ({ key: id }))],
  });
}

export function addMajors(data: { major_name: string; status: number }) {
  return http({
    url: '/addMajors.do',
    method: 'post',
    data: data,
  });
}

export function modifyMajors(data: { major_name: string; status: number; id: number }) {
  return http({
    url: '/updateMajors.do',
    method: 'post',
    data: {
      ...data,
      key: data.id,
    },
  });
}

export function getSubject() {
  return http({
    url: '/selectSubjects.do',
  });
}

export function modifySubject({
  id: key,
  subject_name,
  major_name,
  status,
}: {
  id: number;
  subject_name: string;
  major_name: string;
  status: number;
}) {
  return http({
    url: '/updateSubject.do',
    method: 'post',
    data: {
      key,
      subject_name,
      major_name,
      status,
    },
  });
}

export function deleteSubject(ids: number[] | string[]) {
  return http({
    url: '/deleteSubject.do',
    method: 'post',
    data: [...ids.map((id) => ({ key: id }))],
  });
}

export function addSubject(data: { subject_name: string; major_name: string; status: number }) {
  return http({
    url: '/addSubject.do',
    method: 'post',
    data: data,
  });
}
